Skip to content

feat!: retire event types and personal-data categories, and redact by envelope - #384

Open
benatespina wants to merge 33 commits into
mainfrom
feat/retired-event-types
Open

benatespina wants to merge 33 commits into
mainfrom
feat/retired-event-types

Conversation

@benatespina

Copy link
Copy Markdown
Member

What it does

PR 2 of schema evolution (0.6.0): event types and personal-data categories can be retired, and a redaction reaches fields by what the stored event holds.

  • Retired event types. An aggregate retires a type it no longer records with a module that exports only export const retired = true. Folds skip it; its events are read as stored. bounda generate refuses a retired module that exports anything else, an upcaster next to it, and a process handler, policy or projection named after it; boot refuses an on, a process config or a correlate that names it. A delayed policy run whose policy no longer handles its event's type is dropped and settled with a warning. A process's dead letter names the instance it failed in (instanceId).
  • Start refuses orphan types. An app, a rebuild, bounda forget-ledger prune and bounda forget-ledger stranded refuse a store holding events of a type of one of the app's aggregates that no module names, and a retired type whose events opened streams of an aggregate whose state begin sets up.
  • Sealing a retired type's personal data. Every start records what each event type marks personal, once per set of marks, in bounda_event_marks. The backfill seals what a retired type still holds in the clear by those marks; where sets disagree, the set a walk last sealed the whole store under with no instance on other marks running (sealed_through, read fresh) settles it. A retired type no start recorded marks for, whose marks seal in a category the file neither declares nor retires, or whose marks disagree with no such walk, is refused at start and again by the backfill, an export and a redaction. Failures and letters of a retired type are sealed for the person the marks the store holds name when they are filed.
  • Redaction by envelope (E37). redact reaches any field of every event type, a retired type and a field no longer marked included, by what the stored event holds; the export and the tenant export follow the envelope too. Settling a redaction reaches an old value written after it in any event of the person, one of an aggregate or a process this code no longer has included.
  • Retiring personal-data categories (E38). A category is retired with retired: true, keeping its whole declaration; it leaves PersonalCategoryName (RetiredPersonalCategoryName names it where it is still taken or reported). The store records every category a key was given in and every category a stored write names (restrictions and their lifts, forgettings of a person or a tenant, redactions, disclosures, recipient declarations, forget ledger entries); a start, a rebuild, prune and stranded refuse a recorded category the file neither declares nor retires.

Closes E12, E13, E14, E15, E16, E21, E32, E33, E34, E37 and E38.

Breaking changes

  • A store holding events of a type no module names, or of a retired type that opened streams of an aggregate whose state begin sets up, refuses the start, a rebuild, prune and stranded (ConfigurationError). Retire the type, or keep its module.
  • A retired type the store cannot seal (no recorded marks, a dropped category, unsettled marks) is refused the same way. Deploy once with every module before retiring anything.
  • A category the store recorded that bounda.personal-data.ts neither declares nor retires refuses the start, a rebuild, prune and stranded, forgetting nothing, where its keys were forgotten at once before. The migration records the categories the writes the store already holds name, so the first start after upgrading may refuse a category dropped earlier: retire it.
  • A redaction of a field the event does not hold, or holds sealed for another person, is refused with ValidationError instead of resolving without sealing anything.
  • Adapters of your own: EventStore gains recordMarks, marksOf and recordSealed; StoredEventType gains opened; StoredDeadLetter gains instanceId; StorageTransaction gains checkpointStore; PersonalKeyStore gains recordCategories. The contracts cover them.
  • Storage migration on SQLite (v16) and PostgreSQL (v17).

Gates

  • pnpm check with Docker running: exit 0 (407 files; 8482 tests passed, 60 skipped).
  • pnpm test:coverage: exit 0 (lines 99.07%, statements 98.72%, functions 97.89%, branches 96.33%). The lines and branches thresholds are raised to 99.0 and 96.2.
  • pnpm test:types: exit 0. pnpm docs:build: exit 0.
  • Stryker over the lines this branch changes: core 1522 killed, 5 timed out, 50 survived or not covered; cli 122 killed, 2 survived; postgresql 56 killed, 1 survived. Each remaining mutant is equivalent: a guard that only narrows a type or skips work that would give the same result, a fallback an earlier check makes unreachable, or a sort that only orders lock taking.

Left for a separate PR

  • A subscriber's last failure is written outside any transaction: a backfill that seals the set between the fresh read and the write files it for the person the marks named a moment before. Closing it needs subscriberFailures in StorageTransaction.
  • A frozen tenant's pending recipient declarations record their categories only when the thaw writes them, so a deploy that drops one meanwhile is refused only then.
  • The backfill reads the database alone: forget ledger intentions written before the upgrade and not yet committed are recorded by the reconciliation that commits them, and refused by the start after it.

…y start records

Squashed from the PR 2 sessions so far, to rebase onto the merged PR 1:

- feat(core): retire event types, refuse types no module names and reach a retired event's process
- feat(cli): generate retired event types
- feat(core): export and redact a retired event type's personal data by its envelopes
- test(core): close every connection before restoring a SQLite backup in the retired personal data tests
- feat(core): record event type marks, the kinds that opened a stream and each process letter's instance
- test(core): restore the marks and the kinds that opened a stream with a copy, and migrate a SQLite copy taken before them
- feat(core): seal retired event types by the marks every start records
- fix(core): never write back in the clear what an upcast carries or makes from a sealed value under a key no schema declares
- test(core): seal retired types end to end across rolling deploys, A to B to A marks, frozen and forgotten tenants
- test(core): refuse a rebuild and a ledger prune over a retired type no start recorded marks for
… other marks see it run

A held walk returned before taking the lease, which then lapsed: an instance on other marks read these as stopped, rewrote events in a shape they may not read, called itself caught up and removed their rows, the hold included. The held instance now passes every follow interval to renew the lease, and nextDueAt still waits for the hold's end.
…f marks

bounda_event_marks gains sealed_through, in the unreleased migration. EventStore.recordSealed raises it on the sets given and clears it on the type's other sets sealed no further, so the set sealed last holds the highest: monotone, fenced and staged in transactions like recordMarks, on memory, SQLite and PostgreSQL.
…ast sealed under alone

A backfill walk that catches up with no instance on other marks running records its sets sealed through its position. StoredMarks.authority names the type's set sealed last, and retiredMarksOf takes a field's category from it when it marks the field for the event's person, or else from the one category every own set gives, leaving the field in the clear otherwise. checkRetiredMarks refuses, at start, rebuild and prune, a retired type whose recorded marks give a field different categories that no such walk settled, so the category no longer depends on the order sets were first recorded in.
… whatever person other sets named

A retired type's field marked for different person fields and in different
categories no longer refuses the start once a walk sealed every value under a
set that marks it. A value left in the clear takes that set's category and the
person it names; one whose event names somebody else stays in the clear, as
that walk left it, and what other sets sealed keeps its person.
…since it read none running, and read the marks afresh where retired types are sealed

A start takes its walk's lease before it reads the marks the store recorded,
so a walk of other code that read none running records nothing after them.
The lease is taken and renewed in a transaction, and a walk records its sets
sealed in one that first checks no lease of other marks changed since its pass
read them: transactions run one at a time on every adapter, so the two never
interleave. StorageTransaction carries the checkpoint store for that.

The walk, exports and redactions resolve a retired type's fields by the marks
the store holds when they run, not those of the start, and the walk checks
them again in the transaction that seals each person's events. Marks that no
longer settle a retired type hold the walk with its error, refuse exports and
redactions with the start's message, and the next start refuses.
… recorded keys in a category the app neither declares nor retires

A category of bounda.personal-data.ts takes `retired: true` with its whole declaration: no field,
call or decision marks it any more, its data keeps its retention and exemptions and is never
forgotten at once, and the inventory and the exports say it is retired (formats: export 3,
inventory 3, tenant export 10).

The start, the prune with no app and the stranded listing refuse every category the store
recorded keys in that the app neither declares nor retires, and build their rules per database
from what it recorded, so a category recorded since stays one only newer code declares. A retired
type whose recorded marks seal in such a category is refused too (EV2-aa). The start checks the
marks before it records them, so a refused start records none.
…egister them from the generator

`RetiredPersonalCategoryName` joins `PersonalCategoryName` wherever a category already stored is
named: what forget, restrict and unrestrict take, and every forgetting, restriction, redaction,
recipient and export that reaches one. `personal(...)`, `.personal(...)`, decisions and recipient
declarations still take categories in use alone. The generator registers the retired names as
`retiredPersonalCategories`, and the CLI's inventory marks a retired category.
…the stored event holds

`RedactedFields.fields` offers the fields an event type marks now by name and takes any other.
Every current event type and every lifecycle event that carries a process's state is a target,
one that marks nothing now included. `redact` no longer refuses a field because its type does not
mark it: it reaches each field by its envelope, as it does a retired type's, so a value sealed
under an earlier mark is redacted. It refuses a field held in the clear the type does not mark
now, one sealed for another person, one the event does not hold, and a stream and type the app
knows nothing of, saying which.
…e holds name when they are filed (EV2-ai)

A delayed policy's dead letter and a subscriber's last failure named the
person of a retired type's event by the sets of marks the start read. A walk
of other code that caught up alone since may name another. Both now read the
sets afresh; the letter's commit reads them again in its transaction, which
runs one at a time with the one a walk records its sets sealed in, and seals
the letter again when they name someone else. Policies and processes react to
no retired type, so their letters never name one.
…retired, not declared only (EV2-ak)

A forgetting, a restriction or a recipient notice may name a retired
category; the casts that built their payloads said a declared one.
…t only those keys were added in (EV2-aj)

A category only a restriction, a forgetting, a redaction, a disclosure, a
recipient declaration or a forget ledger entry named could be dropped from
bounda.personal-data.ts without retiring it, leaving stored writes that name
a category the app no longer knows.

- PersonalKeyStore.recordCategories records categories in the catalogue,
  in the caller's transaction (memory, SQL; fenced as a write).
- Runtime events, disclosures and recipient declarations record the
  categories they name in the transaction that writes them; forget ledger
  entries record theirs before the ledger takes them.
- The unreleased migration (SQLite v16, PostgreSQL v17) backfills the
  catalogue from runtime events, restrictions, disclosures, declared
  recipients and forgotten counts (fillNamedCategoriesStatements).
- The refusal now reads "categories the store has recorded".

BREAKING CHANGE: an adapter's PersonalKeyStore implements recordCategories.
…lope, and upgrade to 0.6.0

Changing events gains retiring an event type and what a start refuses,
with every message. Personal data gains retiring a category, the
recorded-categories refusal, sealing a retired type by recorded marks,
redaction's five outcomes and the export, inventory and tenant-export
versions. Adapters gain what an adapter of your own implements since
0.6.0; deployment, dead letters, conventions, CLI, errors, GDPR,
limitations, read models and project layout follow.
… code neither declares nor retires

A rebuild with no app checked the store's event types and the marks of its
retired types as a start does, but not its recorded categories: code that
dropped a category rebuilt where its start would be refused.
…efusal and recordCategories

Widen what records a category to a key, restrictions and their lifts,
forgettings, redactions, disclosures, recipient declarations and forget
ledger entries; note that the migration records what stored writes name, so
the first start after upgrading may refuse a category dropped earlier; and
add PersonalKeyStore.recordCategories to an adapter of one's own and to the
changeset.
…s, and drop the lease's unused checkpoint calls
…, the stored marks, the exports and the redaction targets

Simplify three reads that could not change a result (a set's marks, an event
type's openings, an event that names nobody), and keep a set that marks nothing
as null in memory, as the SQL stores do.
…of an aggregate or process this code no longer has

The settle of a redaction looked only at events whose type this code
reaches, so an instance of earlier code that wrote an old value into a kind
this code reads as stored left it sealed under the person's key, where the
tenant export opens it. Reach every event of the person by its envelopes.
… sealed, the hold's rest and resealing a retired type's events
@pkg-pr-new

pkg-pr-new Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@bounda-dev/cli

npm i https://pkg.pr.new/@bounda-dev/cli@384

@bounda-dev/cloudflare

npm i https://pkg.pr.new/@bounda-dev/cloudflare@384

@bounda-dev/core

npm i https://pkg.pr.new/@bounda-dev/core@384

create-bounda

npm i https://pkg.pr.new/create-bounda@384

@bounda-dev/postgresql

npm i https://pkg.pr.new/@bounda-dev/postgresql@384

@bounda-dev/react-router

npm i https://pkg.pr.new/@bounda-dev/react-router@384

@bounda-dev/sqlite

npm i https://pkg.pr.new/@bounda-dev/sqlite@384

commit: 186fe8d

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant